
$(function(){
	download.run();	
});

var download = {	
		run: function(){
			this.__init__();			
			this._start_();
			this._bind_events();
		},
		
		__init__: function(){
			this.itemUrl = "";
			this.title = "";
		},
		
		_start_: function(){			
			var ua = navigator.userAgent;
			if (ua.indexOf('Mac') >= 0) {
				this.$alertDialog = $(".donwolad-alert-mac");
			} else {
				this.$alertDialog = $(".donwolad-alert");
			}
		},
		
		_bind_events: function(){	
			$(".download_btn").live('click',function() {
				download.itemUrl = $(this).attr("itemUrl");
				download.title = $(this).attr("itemTitle");
				var website = $(this).attr("website");
				if (website == "Moviefone") {
					download.$alertDialog = $(".donwolad-alert-no-support");
					download.vdInstalled = false;
				} else {
					download.vdInstalled = vd.check();
				}
				if (!download.vdInstalled) {
					download.$alertDialog.dialog({
						submit : function() {
							vd.keep();
							_gaq.push([ '_trackEvent', 'Movice', 'Download', download.itemUrl ]);
							vd.go(download.itemUrl, download.title);
							download.vdInstalled = true;
						}
					});
					download.$alertDialog.dialog('open');
				} else {
					_gaq.push([ '_trackEvent', 'Movice', 'Download', download.itemUrl ]);
					vd.go(download.itemUrl, download.title);
				}
				return false;
			});
		}
		
		
		
};

